﻿using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebApplication2.Class;

namespace WebApplication2
{
    public partial class FlowChart : System.Web.UI.Page
    {
        DataForFlowChart g = new DataForFlowChart();
        protected void Page_Load(object sender, EventArgs e)
        {
            g = (DataForFlowChart)Session["DataForFlowChart"];
            ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load("C:\\Users\\bioinfocomm\\Desktop\\New folder (3)\\ itreatment\\WebApplication2\\Hemodialysis Flowchart.rpt");
            DataSet ds = new DataSet();
            ds = testing();
            cryRpt.SetDataSource(ds.Tables[0]);
            cryRpt.Subreports[0].SetDataSource(ds.Tables[1]);
            cryRpt.Subreports[1].SetDataSource(ds.Tables[2]);
            cryRpt.Subreports[2].SetDataSource(ds.Tables[3]);
            CrystalReportViewer1.ReportSource = cryRpt;
            CrystalReportViewer1.RefreshReport();
        }

        public DataSet testing()
        {
            ReportDocument report = new ReportDocument();
            DataTable dt1 = new DataTable();
            DataTable dt2 = new DataTable();
            DataTable dt3 = new DataTable();
            DataTable dt4 = new DataTable();
            DataSet ds = new DataSet();

            SqlConnection conn = new SqlConnection();
            SqlDataAdapter da = new SqlDataAdapter();

            conn.ConnectionString = "Data Source = 192.168.1.156; Initial Catalog= HeDINursing; User ID = sa; Password = admin123";
            conn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "[sp_HDFlowChart3.1]";

            cmd.Parameters.Add("@pName", g.pName);
            cmd.Parameters.Add("@fromDate", g.Date_Time1);
            cmd.Parameters.Add("@mrn", g.mrn);
            cmd.Parameters.Add("@PID", g.mrn);
            cmd.Parameters.Add("@RunNo", g.RunNo);
            da.SelectCommand = cmd;
            da.Fill(dt1);

            if (dt1.Rows.Count > 0)
            {

                SqlCommand cmd1 = new SqlCommand();
                cmd1.Connection = conn;
                cmd1.CommandType = CommandType.StoredProcedure;
                cmd1.CommandText = "[sp_HDFlowChart_subrpt_Events3.0]";
                cmd1.Parameters.Add("@HDTreatmentID", g.HDTreatmentID);
                da.SelectCommand = cmd1;
                da.Fill(dt2);


                SqlCommand cmd2 = new SqlCommand();
                cmd2.Connection = conn;
                cmd2.CommandType = CommandType.StoredProcedure;
                cmd2.CommandText = "[sp_HDFlowChart_subrpt_Meds3.0]";
                cmd2.Parameters.Add("@HDTreatmentID", g.HDTreatmentID);
                da.SelectCommand = cmd2;
                da.Fill(dt3);

  
                SqlCommand cmd3 = new SqlCommand();
                cmd3.Connection = conn;
                cmd3.CommandType = CommandType.StoredProcedure;
                cmd3.CommandText = "[sp_HDFlowChart_subrpt_Viro3.1]";
                cmd3.Parameters.Add("@PatientID", g.PatientID);
                da.SelectCommand = cmd3;
                da.Fill(dt4);

            }

            ds.Tables.Add(dt1);
            ds.Tables.Add(dt2);
            ds.Tables.Add(dt3);
            ds.Tables.Add(dt4);
            return ds;
        }

    
    }
}